Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: Improve enum support #3861

Merged
merged 15 commits into from
Jun 26, 2024

Conversation

hughsimpson
Copy link
Contributor

@hughsimpson hughsimpson commented Jun 19, 2024

Various improvements to enum support in codegen:

  • Supports enum serdes for zio-json (scala 2.x only)
  • Supports inline enum definitions (on both paths and schemas)
  • Supports Option[Enum], List[Enum], and Option[List[Enum]]* query params
  • Supports a wider range of enum values

* Note that Option[List[T]] is only supported for unexploded params -- for exploded params, there's no distinction betwen an empty list and an absent value; so the required field will be ignored for exploded query params.

Also adds some support for explode on query params; will now default to explode = true (as per the spec), but also supports explode = false. It still only supports arrays in form style for now.

Since the generator runs with scala 2.12 and does not have access to sttp.tapir.model.CommaSeparated I've had to implement case class CommaSeparatedValues and case class ExplodedValues in the generated files, which is a shame, but should be okay...

@@ -1 +1 @@
sbt.version=1.3.13
sbt.version=1.10.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumping sbt fixes sbt scripted on Java 18+

@adamw adamw requested a review from kciesielski June 19, 2024 12:41
@hughsimpson hughsimpson changed the title codegen: Improve enum supports codegen: Improve enum support Jun 19, 2024
@hughsimpson
Copy link
Contributor Author

hughsimpson commented Jun 19, 2024

Sorry this pr conflates a few things together, but I didn't have the energy to split it out only to resolve conflicts down the line.. I think it represents a decent improvement, though, and hopefully none of the functionality is really contentious.

@hughsimpson hughsimpson force-pushed the generate_inline_enums branch 2 times, most recently from 3aebac2 to cf88667 Compare June 19, 2024 22:08
@kciesielski
Copy link
Member

Impressive! A few nitpick comments so far, I'll finish the review later today or tomorrow.

@hughsimpson
Copy link
Contributor Author

Thanks for the comments 🙏 all very sensible suggestions (especially around that Seq[(Option[String], Seq[(String, String, Option[String])])] 😬 -- took me a few mins to unpick that myself 😅). Have pushed up some fixes to address them

@hughsimpson
Copy link
Contributor Author

hughsimpson commented Jun 22, 2024

Test failure seems to be... not sure exactly. It ends with

2024-06-22T14:01:01.9474905Z �[0m[�[0m�[0minfo�[0m] �[0m�[0m�[32mAll tests passed.�[0m�[0m
2024-06-22T14:12:30.0226099Z �[34mclientTestServer�[0m ... killing ...
2024-06-22T14:12:40.0077417Z ##[error]Final attempt failed. Timeout of 900000ms hit

-- clientTestServer seems to be related to reStart / mainClass := Some("sttp.tapir.client.tests.HttpServer"), under clientTestServer in the build file? I don't even know if that's what's actually timing out, but tests pass for me locally.

Anyway I think the tests have generally been less flakey of late and I appreciate that, but I mentioned the observation in case it helped shed some light on what the (presumably timing) issue actually is.

@kciesielski
Copy link
Member

@hughsimpson Sorry for the flaky tests, I'm still investigating what's causing these freezes #3827
Don't worry about it, I'll rerun whatever needs rerunning until it succeeds for now.

@kciesielski
Copy link
Member

I guess this part of docs can be updated? https://tapir.softwaremill.com/en/latest/generator/sbt-openapi-codegen.html#json-support

Currently, string-like enums in Scala 2 depend upon the enumeratum library ("com.beachape" %% "enumeratum"). For Scala 3 we derive native enums, and depend on "io.github.bishabosha" %% "enum-extensions" for generating query param serdes. Other forms of OpenApi enum are not currently supported.

Particularly "Other forms of OpenApi enum are not currently supported."?

@hughsimpson hughsimpson force-pushed the generate_inline_enums branch from 94eb307 to c384b9d Compare June 24, 2024 11:04
@kciesielski
Copy link
Member

@hughsimpson Thanks again, looks good!

@kciesielski kciesielski merged commit 9032555 into softwaremill:master Jun 26, 2024
21 checks passed
@hughsimpson hughsimpson deleted the generate_inline_enums branch June 26, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants